package cn.xkai.exercise.a;

/**
 * @description: 寻找旋转排序数组中的最小值
 * 自己的思路：双指针找临界点，小于左边大于右边，或者小于右边
 * 借鉴的思路：同理
 * @author: kaixiang
 * @date: 2022-06-29
 **/
public class Solution21 {
    public int findMin(int[] nums) {
        int len = nums.length, left = 0, right = len - 1, min = 0;
        while (left <= right) {
            if (nums[right] < nums[left] && nums[right] < nums[right - 1]) {
                min = right;
                break;
            }
            if (nums[left] <= nums[right]) {
                min = left;
                break;
            }
            left++;
            right--;
        }
        return nums[min];
    }

    public static void main(String[] args) {
        int[] nums = {3, 2};
        Solution21 solution21 = new Solution21();
        System.out.println(solution21.findMin(nums));
    }
}
